#include "PopupUserMessageReaction.hpp"

using namespace std;
using namespace Popup;

RateUserMessageWrapper::RateUserMessageWrapper(const Message *p_message)
: AbstractMessage(POPUP_MSG_TYPE_RATE_MESSAGE)
{
  AbstractMessage::deserialize(p_message);
}

bool RateUserMessageWrapper::onSend()
{
  bool _rc = payloadAddLongLong(SOURCE_MSG_ID, reaction.msgID);

  if (_rc) {
    _rc = payloadAddLongLong(SOURCE_MSG_THREAD_ID, reaction.threadID);
  }
  if (_rc) {
    _rc = payloadAddLong(TARGETS, reaction.targets);
  }
  if (_rc) {
    payloadAddLong(SOURCE_MSG_SENDER, reaction.msgSenderID);
  }
  if (_rc) {
    payloadAddLong(RATE_SENDER_ID, reaction.rateSenderID);
  }
  if (_rc) {
    payloadAddShort(RATED_ITEM, reaction.rateItem);
  }
  if (_rc) {
    payloadAddBoolean(IS_UNDO, reaction.isUndo);
  }

  return _rc;
}

bool RateUserMessageWrapper::onReceive()
{
  bool _rc = payloadGetLongLong(SOURCE_MSG_ID, msgID);

  if (_rc) {
    _rc = payloadGetLongLong(SOURCE_MSG_THREAD_ID, threadID);
  }
  if (_rc) {
    _rc = payloadGetLong(TARGETS, targets);
  }
  if (_rc) {
    _rc = payloadGetLong(SOURCE_MSG_SENDER, msgSenderID);
  }
  if (_rc) {
    _rc = payloadGetLong(RATE_SENDER_ID, rateSenderID);
  }
  if (_rc) {
    unsigned short _reactionTypeValue = 0;
    _rc = payloadGetShort(RATED_ITEM, _reactionTypeValue);
    rateItem = (UserRateItem) _reactionTypeValue;
  }
  if (_rc) {
    payloadGetBoolean(IS_UNDO, isUndo);
  }

  return _rc;
}
